/**
 * Created by zhtt on 2017/5/7.
 */
supermarketApp.controller("GoodsCtrl", ["$scope", "$timeout","GoodsService",function ($scope, $timeout,GoodsService) {
    $scope.limit = 20;
    $scope.loading = false;

    $scope.data = {
        '在建': {
            page: 1,
            limit: $scope.limit,
            totalPages: 0,
            totalElements: 0,
            items: [],
            callback:function (page) {
                chooseTab('在建');
            }
        },
        '开建': {
            page: 1,
            limit: $scope.limit,
            totalPages: 0,
            totalElements: 0,
            items: [],
            callback:function (page) {
                chooseTab('开建');
            }
        }
    };
    $scope.chooseTab = chooseTab;
    var url="js/data/dict.json";
    GoodsService.getOrderType(url,function (data) {
        $('#tree').treeview({
            color: "#428bca",
            expandIcon: 'glyphicon glyphicon-chevron-right',
            collapseIcon: 'glyphicon glyphicon-chevron-down',
            nodeIcon: 'glyphicon glyphicon-bookmark',
            data: data.goodsType});
    });
    function chooseTab(type) {
        var goodsListUrl="js/data/goodsList.json";
        $scope.loading = true;
        GoodsService.getGoodsList(goodsListUrl,function (data) {
            $scope.loading = false;
            if (data) {
                var target = $scope.data[type||'在建'];
                target.page = 1;
                target.items = data.items;
                target.totalPages = data.totalPages;
                target.totalElements = data.totalElements;
                target=null;
                // $scope.data[type] = target;
            }
        });
    }
}]);
